var ws, spage, uid, isrepeat = 0, isshock = 1, parentPg;
document.addEventListener('plusready',function(){
	parentPg = plus.webview.getWebviewById('index.html');
	ws = plus.webview.currentWebview();
	spage = ws.spage;
	uid = plus.storage.getItem('uid');
	//星期选择
	$('.wek .we').on('tap',function(){
		var week = '';
		$('input[name=radio1]:checked').each(function(){
			week += $(this).siblings('label').text()+' ';
		})
		console.log(week);
		week?$('.week').text(week):$('.week').text('选择星期');
	})
	//是否重复
	$('.chongfu').on('tap',function(){
		if(this.classList.contains('mui-active')){//开启
			isrepeat = 1;
		}else{//关闭
			isrepeat = 0;
		}
	})
	$('.csure').on('tap', function(){
		$('.cpill').text($('.cpills').val());
	})
	$('.fsure').on('tap', function(){
		$('.fpill').text($('.fpills').val());
	})
	//是否震动
	$('.zhendong').on('tap',function(){
		if(this.classList.contains('mui-active')){//开启
			isshock = 1;
			$('.shock').text('震动');
		}else{//关闭
			isshock = 0;
			$('.shock').text('关闭震动');
		}
	})
	//选择铃声
	$('.bell').click(function(){
		goNewPage('me-remind-bell.html',{spage:ws.id})
	})
	//点击完成
	$('.overWarn').on('tap',function(){
		var xingqi = $('.week').text();
		var cpills = $('.cpills').val();//吃药注意事项
		var fpills = $('.fpills').val();//家庭成员注意事项
		var hours = $('.hours').text();//选择的时
		var minutes = $('.minutes').text();//选择的分
		var bell = $('.lingsheng').text();//铃声
//		console.log(xingqi+" "+cpills+" "+fpills+" "+isrepeat+" "+bell);return;
		if(xingqi == '选择星期' || !cpills.trim() || !fpills.trim() || !hours.trim() || !minutes.trim()){
			toast('请补全信息');return;
		}
		showWating();
		$.ajax({
			type:"get",
			url:apiRoot+"?m=home&c=medicinal&a=addWarn",
			data :{
				week : xingqi,
				takepills :cpills,
				familypills :fpills,
				hours :hours,
				minutes :minutes,
				isrepeat :isrepeat,
				isshock :isshock,
				uid :uid,
				bell :bell,
				tid :1//用户自添提醒
			},
			dataType :'json',
			success :function(data){
				plus.nativeUI.closeWaiting();
				console.log(JSON.stringify(data));
				if(data > 0){
					toast('新增成功');
					if(spage){
						plus.webview.getWebviewById(spage).reload();
						parentPg.evalJS('searchWarn()');
					}
					setTimeout(function(){
						ws.close();
					},2000);
				}
			},
			error :function(e){
				console.log(JSON.stringify(e));
				errortoast();
			}
		});
	})
},false)

window.addEventListener('bell',function(event){
	var bell = event.detail.bell;
	console.log(bell);
	$('.lingsheng').text(bell);
},false)